package cn.topevery.garden.dal.logic;

import cn.topevery.garden.dal.dao.MaintenanceFileDao;
import cn.topevery.garden.entity.po.MaintenanceFile;
import cn.topevery.garden.entity.query.MaintenanceFileQuery;
import cn.topevery.garden.entity.vo.MaintenanceFileVO;
import cn.topevery.garden.framework.base.BaseLogic;
import hw.topevery.framework.db.base.BaseEntityDao;
import hw.topevery.framework.db.entity.DataPager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 保养记录 附件表
 *
 * @author code-generate
 * @date 2022-02-17
 */
@Service
public class MaintenanceFileLogic extends BaseLogic<MaintenanceFile> {
    @Autowired
    MaintenanceFileDao maintenanceFileDao;

    @Override
    public BaseEntityDao<MaintenanceFile, Integer> getDao() {
        return maintenanceFileDao;
    }

    

    /**
     * 获取列表
     *
     * @param query
     */
    public DataPager<MaintenanceFileVO> listPage(MaintenanceFileQuery query) {
        return maintenanceFileDao.listPage(query);
    }

    /**
     * 根据自增id批量删除
     *
     * @param ids
     */
    public void deleteBatchById(String userId,Integer[] ids) {
        maintenanceFileDao.delete(userId, ids);
    }

    /**
     * 根据自增id保存或者更新
     *
     * @param maintenanceFile 实体
     */
    public void saveOrUpdate(String userId, MaintenanceFile maintenanceFile){
        maintenanceFileDao.saveOrUpdate(userId,maintenanceFile);
    }

    /**
         * 根据自定义列值来获取对象
         */
    public MaintenanceFile getEntityByColumn(String key, String value) {
        return maintenanceFileDao.getEntityByColumn(key, value);
    }

    public List<MaintenanceFile> getListByMainId(Integer mainId) {
        return maintenanceFileDao.getListByMainId(mainId);
    }

    public void saveOrUpdate(String userId, Integer mainId, List<MaintenanceFile> fileList) {
        maintenanceFileDao.deleteByMainId(mainId);
        for (MaintenanceFile maintenanceFile : fileList) {
            maintenanceFile.setMainId(mainId);
            maintenanceFileDao.saveOrUpdate(userId, maintenanceFile);
        }
    }

    public void deleteByMainIds(Integer[] ids) {
        maintenanceFileDao.deleteByMainIds(ids);
    }
}
